\ProvidesPackage{fig_problem}

\RequirePackage{tikz}

\RequirePackage{xcolor}
\definecolor{bg_gray}{RGB}{230, 230, 230}
\definecolor{c_blank}{RGB}{147, 254, 123}
\definecolor{c_comp}{RGB}{247, 130, 255}

\newcommand{\drawGZJN}{

    % Frame
    \draw (-1, -1) -- (21, -1) -- (21, 8) -- (-1, 8) -- (-1, -1);
    \draw (11, -1) -- (11, 8);

    \node[scale = 1.5] at (-0.4, 7.4) {(a)};
    \node[scale = 1.5] at (11.6, 7.4) {(b)};

    \begin{scope}[xshift=1cm]
        
        % The surrounding box
        \draw[thick, rounded corners=8pt, fill=bg_gray] (-0.4, -0.4) rectangle (4.4, 6.4);

        % Fill blank color
        \draw[draw=none, fill=c_blank] (0, 0) rectangle (2, 1);
        \draw[draw=none, fill=c_blank] (0, 1) rectangle (4, 6);

        % The inner grids
        \draw (0, 0) -- (2, 0);
        \draw (0, 0) -- (0, 6);
        \draw (4, 1) -- (4, 6);
        \draw (1, 0) -- (1, 6);
        \draw (2, 0) -- (2, 6);
        \draw (3, 1) -- (3, 6);
        \draw (0, 1) -- (4, 1);
        \draw (0, 2) -- (4, 2);
        \draw (0, 3) -- (4, 3);
        \draw (0, 4) -- (4, 4);
        \draw (0, 5) -- (4, 5);
        \draw (0, 6) -- (4, 6);

        % The labels
        \node at (0.5,5.5) {丑};
        \node at (1.5,5.5) {子};
        \node at (2.5,5.5) {甲};
        \node at (3.5,5.5) {乙};
        \node at (0.5,4.5) {寅};
        \node at (1.5,4.5) {卯};
        \node at (2.5,4.5) {丁};
        \node at (3.5,4.5) {丙};
        \node at (0.5,3.5) {巳};
        \node at (1.5,3.5) {辰};
        \node at (2.5,3.5) {戊};
        \node at (3.5,3.5) {己};
        \node at (0.5,2.5) {午};
        \node at (1.5,2.5) {未};
        \node at (2.5,2.5) {辛};
        \node at (3.5,2.5) {庚};
        \node at (0.5,1.5) {酉};
        \node at (1.5,1.5) {申};
        \node at (2.5,1.5) {壬};
        \node at (3.5,1.5) {癸};
        \node at (0.5,0.5) {戌};
        \node at (1.5,0.5) {亥};

        \draw[thick, fill=c_comp] (5.5, 2.5) rectangle (7.5, 3.5);
        \draw[dotted, thin] (6.5, 2.5) -- (6.5, 3.5);
        \node[scale=1.2] at (8, 3) {$\times 10$};

    \end{scope}

    \begin{scope}[xshift=14cm]
        
        % The surrounding box
        \draw[thick, rounded corners=8pt, fill=bg_gray] (-0.4, -0.4) rectangle (4.4, 6.4);

        % Fill blank color
        \draw[draw=none, fill=c_comp] (0, 0) rectangle (2, 1);
        \draw[draw=none, fill=c_comp] (0, 1) rectangle (4, 6);
        \draw[draw=none, fill=c_blank] (1, 3) rectangle (2, 4);
        \draw[draw=none, fill=c_blank] (2, 5) rectangle (3, 6);

        % The labels
        \node at (0.5, 5.5) {丑};
        \node at (1.5, 5.5) {子};
        \node at (2.5, 5.5) {甲};
        \node at (3.5, 5.5) {乙};
        \node at (0.5, 4.5) {寅};
        \node at (1.5, 4.5) {卯};
        \node at (2.5, 4.5) {丁};
        \node at (3.5, 4.5) {丙};
        \node at (0.5, 3.5) {巳};
        \node at (1.5, 3.5) {辰};
        \node at (2.5, 3.5) {戊};
        \node at (3.5, 3.5) {己};
        \node at (0.5, 2.5) {午};
        \node at (1.5, 2.5) {未};
        \node at (2.5, 2.5) {辛};
        \node at (3.5, 2.5) {庚};
        \node at (0.5, 1.5) {酉};
        \node at (1.5, 1.5) {申};
        \node at (2.5, 1.5) {壬};
        \node at (3.5, 1.5) {癸};
        \node at (0.5, 0.5) {戌};
        \node at (1.5, 0.5) {亥};

        % Component boader
        \draw[line width = 1.2] (0, 0) -- (0, 6);
        \draw[line width = 1.2] (1, 0) -- (1, 4);
        \draw[line width = 1.2] (2, 1) -- (2, 2);
        \draw[line width = 1.2] (3, 2) -- (3, 6);
        \draw[line width = 1.2] (4, 1) -- (4, 6);
        \draw[line width = 1.2] (0, 0) -- (2, 0) -- (2, 1) -- (4, 1);
        \draw[line width = 1.2] (0, 2) -- (4, 2);
        \draw[line width = 1.2] (1, 3) -- (3, 3);
        \draw[line width = 1.2] (0, 4) -- (2, 4);
        \draw[line width = 1.2] (0, 5) -- (3, 5);
        \draw[line width = 1.2] (0, 6) -- (2, 6);
        \draw[line width = 1.2] (2, 3) -- (2, 6);
        \draw[line width = 1.2] (3, 4) -- (4, 4);
        \draw[line width = 1.2] (3, 6) -- (4, 6);

        \draw (2, 6) -- (3, 6);

    \end{scope}

}

\newcommand{\drawAPuzzleADay}{

    % Frame
    \draw (-1, -1) -- (21, -1) -- (21, 8) -- (-1, 8) -- (-1, -1);

    % The surrounding box
    \draw[thick, rounded corners=8pt, fill=bg_gray] (1.4, -0.4) -- (7.4, -0.4) -- (7.4, 5.4) -- (6.4, 5.4) -- (6.4, 7.4) -- (-0.4, 7.4) -- (-0.4, -0.4) -- (1.4, -0.4);

    % Fill blank color
    \draw[draw=none, fill=c_blank] (0, 0) rectangle (3, 1);
    \draw[draw=none, fill=c_blank] (0, 1) rectangle (7, 5);
    \draw[draw=none, fill=c_blank] (0, 5) rectangle (6, 7);

    % The inner grids
    \draw (0, 0) -- (3, 0);
    \draw (0, 1) -- (7, 1);
    \draw (0, 2) -- (7, 2);
    \draw (0, 3) -- (7, 3);
    \draw (0, 4) -- (7, 4);
    \draw (0, 5) -- (7, 5);
    \draw (0, 6) -- (6, 6);
    \draw (0, 7) -- (6, 7);
    \draw (0, 0) -- (0, 7);
    \draw (1, 0) -- (1, 7);
    \draw (2, 0) -- (2, 7);
    \draw (3, 0) -- (3, 7);
    \draw (4, 1) -- (4, 7);
    \draw (5, 1) -- (5, 7);
    \draw (6, 1) -- (6, 7);
    \draw (7, 1) -- (7, 5);

    % Month labels
    \node at (0.5,6.5) {Jan};
    \node at (1.5,6.5) {Feb};
    \node at (2.5,6.5) {Mar};
    \node at (3.5,6.5) {Apr};
    \node at (4.5,6.5) {May};
    \node at (5.5,6.5) {Jun};
    \node at (0.5,5.5) {Jul};
    \node at (1.5,5.5) {Aug};
    \node at (2.5,5.5) {Sep};
    \node at (3.5,5.5) {Oct};
    \node at (4.5,5.5) {Nov};
    \node at (5.5,5.5) {Dec};

    % Day numbers
    \foreach \x in {0,...,6} {
        \foreach \y in {0,...,4} {
            \pgfmathtruncatemacro{\day}{7*\y+\x+1}
            \ifnum \day < 32
            \node at (\x+0.5,4.5-\y) {\day};
            \fi
        }
    }

    % Draw the components
    \begin{scope}[xshift=8.5cm, yshift=3.5cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (0, 0) -- (1, 0) -- (1, 3) -- (2, 3) -- (2, 4) -- (0, 4) -- (0, 0);
        \draw[dotted, thin] (0, 1) -- (1, 1);
        \draw[dotted, thin] (0, 2) -- (1, 2);
        \draw[dotted, thin] (0, 3) -- (1, 3);
        \draw[dotted, thin] (1, 3) -- (1, 4);
    \end{scope}
    \begin{scope}[xshift=8.5cm, yshift=-0.3cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (0, 0) -- (2, 0) -- (2, 3) -- (0, 3) -- (0, 2) -- (1, 2) -- (1, 1) -- (0, 1) -- (0, 0);
        \draw[dotted, thin] (1, 0) -- (1, 1) -- (2, 1);
        \draw[dotted, thin] (2, 2) -- (1, 2) -- (1, 3);
    \end{scope}

    \begin{scope}[xshift=11.5cm, yshift=3.5cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (1, 0) -- (2, 0) -- (2, 4) -- (1, 4) -- (1, 2) -- (0, 2) -- (0, 1) -- (1, 1) -- (1, 0);
        \draw[dotted, thin] (1, 1) -- (2, 1);
        \draw[dotted, thin] (1, 2) -- (2, 2);
        \draw[dotted, thin] (1, 3) -- (2, 3);
        \draw[dotted, thin] (1, 1) -- (1, 2);
    \end{scope}
    \begin{scope}[xshift=11.5cm, yshift=-0.3cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (0, 0) -- (1, 0) -- (1, 1) -- (2, 1) -- (2, 3) -- (0, 3) -- (0, 0);
        \draw[dotted, thin] (0, 1) -- (1, 1) -- (1, 3);
        \draw[dotted, thin] (0, 2) -- (2, 2);
    \end{scope}

    \begin{scope}[xshift=14.5cm, yshift=3.5cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (2, 1) -- (3, 1) -- (3, 4) -- (0, 4) -- (0, 3) -- (2, 3) -- (2, 1);
        \draw[dotted, thin] (2, 2) -- (3, 2);
        \draw[dotted, thin] (2, 3) -- (3, 3);
        \draw[dotted, thin] (1, 3) -- (1, 4);
        \draw[dotted, thin] (2, 3) -- (2, 4);
    \end{scope}
    \begin{scope}[xshift=14.5cm, yshift=-0.3cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (0, 0) -- (2, 0) -- (2, 2) -- (3, 2) -- (3, 3) -- (1, 3) -- (1, 1) -- (0, 1) -- (0, 0);
        \draw[dotted, thin] (1, 0) -- (1, 1) -- (2, 1);
        \draw[dotted, thin] (1, 2) -- (2, 2) -- (2, 3);
    \end{scope}

    \begin{scope}[xshift=18.5cm, yshift=3.5cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (1, 0) -- (2, 0) -- (2, 2) -- (1, 2) -- (1, 4) -- (0, 4) -- (0, 1) -- (1, 1) -- (1, 0);
        \draw[dotted, thin] (2, 1) -- (1, 1) -- (1, 2);
        \draw[dotted, thin] (0, 2) -- (1, 2);
        \draw[dotted, thin] (0, 3) -- (1, 3);
    \end{scope}
    \begin{scope}[xshift=18.5cm, yshift=-0.3cm, scale=0.95]
        \draw[fill=c_comp, ultra thick] (0, 0) -- (2, 0) -- (2, 3) -- (0, 3) -- (0, 0);
        \draw[dotted, thin] (0, 1) -- (2, 1);
        \draw[dotted, thin] (0, 2) -- (2, 2);
        \draw[dotted, thin] (1, 0) -- (1, 3);
    \end{scope}

}

\newcommand{\drawTriangleGrid}{

    % The surroundings
    \pgfmathsetmacro \xA {3.5 * cos(0)}
    \pgfmathsetmacro \yA {3.5 * sin(0)}
    \pgfmathsetmacro \xB {3.5 * cos(60)}
    \pgfmathsetmacro \yB {3.5 * sin(60)}
    \pgfmathsetmacro \xC {3.5 * cos(120)}
    \pgfmathsetmacro \yC {3.5 * sin(120)}
    \pgfmathsetmacro \xD {3.5 * cos(180)}
    \pgfmathsetmacro \yD {3.5 * sin(180)}
    \pgfmathsetmacro \xE {3.5 * cos(240)}
    \pgfmathsetmacro \yE {3.5 * sin(240)}
    \pgfmathsetmacro \xF {3.5 * cos(300)}
    \pgfmathsetmacro \yF {3.5 * sin(300)}
    \pgfmathsetmacro \xS {(\xA + \xB) / 2}
    \pgfmathsetmacro \yS {(\yA + \yB) / 2}
    \draw[thick, rounded corners=8pt, fill=bg_gray] (\xS, \yS) -- (\xB, \yB) -- (\xC, \yC) -- (\xD, \yD) -- (\xE, \yE) -- (\xF, \yF) -- (\xA, \yA) -- (\xS, \yS);
    
    % Fill color
    \pgfmathsetmacro \xA {3 * cos(0)}
    \pgfmathsetmacro \yA {3 * sin(0)}
    \pgfmathsetmacro \xB {3 * cos(60)}
    \pgfmathsetmacro \yB {3 * sin(60)}
    \pgfmathsetmacro \xC {3 * cos(120)}
    \pgfmathsetmacro \yC {3 * sin(120)}
    \pgfmathsetmacro \xD {3 * cos(180)}
    \pgfmathsetmacro \yD {3 * sin(180)}
    \pgfmathsetmacro \xE {3 * cos(240)}
    \pgfmathsetmacro \yE {3 * sin(240)}
    \pgfmathsetmacro \xF {3 * cos(300)}
    \pgfmathsetmacro \yF {3 * sin(300)}
    \draw[thick, fill=c_blank] (\xA, \yA) -- (\xB, \yB) -- (\xC, \yC) -- (\xD, \yD) -- (\xE, \yE) -- (\xF, \yF) -- (\xA, \yA);

    % Grid
    \foreach \r in {0, 60, 120}{
        \begin{scope}[rotate = \r]
            
            \foreach \i in {-3, ..., 3}{
                \pgfmathsetmacro \y {\i * cos(30)}
                
                \ifnum \i < 0
                    \pgfmathsetmacro \x {3 + \i / 2}
                \else
                    \pgfmathsetmacro \x {3 - \i / 2}
                \fi
                
                \draw (-\x, \y) -- (\x, \y);
            }

        \end{scope}
    }

}